Environment-variables

Environment Variables:

  • in Linux there is 2 types of Variables:
    1. shell variables = denoted by lower-case $shell.
    1. Enviroment variables denoted by upper-case $SHELL
  • these Variables are built in our system or added after installing Tools or application

what Environment Variable do ?

  • it store key=value pair that control process and Interfaces(genome/Wayland) in linux system.
  • Example: SHELL=/bin/zsh
  • Also it can contain multiple values like key=val1:val2:val3.

Viewing Default Environment Variables:

env
printenv


View all Variables

  • we can view all shell and Environment variables.
set | less
  • Utilize grep to FILTER for particular variable.
set | grep HISTSIZE

Screenshot 2025-10-03 020849.png

Changing Variable Value on a Terminal session:

  • this varaible will not availiable globally only limited to that terminal session.
  • if u close the terminal the saved Enviroment variable will reset to the Oraginal Value
  • or the Stored Variable will be Lost after Closing the Terminal.

Example:

EXAMPLE=8.8.8.8

Screenshot 2025-10-03 022931.png

Example of Changing Environment Variable:

  • Changing the Shell Prompt.
  • PS1 is an environment variable in Linux that defines the primary prompt string displayed in the terminal, allowing customization of the command prompt appearance.
PS1='C:\w >'
 # \w = directoey
 # \u = user
 # \h = hostname

Screenshot 2025-10-03 032828.png

Creating global variable to use in multiple session

  • creating the varaible that can be called in multiple terminal sessions.
IP=1.1.1.1
export IP

SCREENSHOST MULTIPLE SESSIONS

  • Set up the Variable to exported
    Screenshot 2025-10-03 035839.png
  • Checking if the the Variable can be called in other terminal sessions Note: I am using tmux.

Screenshot 2025-10-03 035955.png

  • Example use Case of Variable.
    Screenshot 2025-10-03 040435.png